package com.brkj.main;

import java.io.File;

import net.tsz.afinal.FinalHttp;
import net.tsz.afinal.http.AjaxCallBack;
import com.brkj.httpInterface.BaseAjaxParams;

import android.content.Context;
import android.content.Intent;
import android.os.Environment;

import com.brkj.model.DS_MyInfo;
import com.brkj.util.ImgShow;
import com.brkj.util.JsonUtil;
import com.brkj.util.MyApplication;
import com.brkj.httpInterface.HttpInterface.HIF_GetPersnalInfo;

public class MyInfo extends DS_MyInfo{

	private String MY_HEAD_IMG = Environment.getExternalStorageDirectory() + "/brkj/MyHeadImg/" + "my.jpg";
	public static String MY_HEAD_IMG_PATH = Environment.getExternalStorageDirectory() + "/brkj/MyHeadImg/";
	public static String MY_HEAD_IMG_NAME = "my.jpg";

	private Context context;
	private DS_MyInfo myInfo;
	public MyInfo(Context context){
		this.context = context;
	}
	
	public String getMyHeadImgPath(){
		return MY_HEAD_IMG;
	}
	
	public File getMyHeadImg(){
		File img = new File(MY_HEAD_IMG);
		return img;
	}
	public void getInfoFromNet() {
		if(MyApplication.myUserID == ""){
			return;
		}
		
		BaseAjaxParams params = new BaseAjaxParams();
		params.put(HIF_GetPersnalInfo.params.UserID, MyApplication.myUserID);
		
		FinalHttp fh = new FinalHttp();
		fh.post(HIF_GetPersnalInfo.address, params, new AjaxCallBack<Object>() {

			@Override
			public void onSuccess(Object t) {
				// TODO Auto-generated method stub
				super.onSuccess(t);
				myInfo = JsonUtil.fromJson((String)t, DS_MyInfo.class);
				if(myInfo != null){
					myInfo.saveInfo();
					MyApplication.updateMyinfo();
					if(ImgShow.headFb != null){
						ImgShow.headFb.clearCache();
					}
					
					
					Intent intent = new Intent();
					intent.setAction("com.brkj.myInfoUpdate");
					context.sendBroadcast(intent);
				}

			}
			
		});
		
	}
}
